<?php
	
	$config = array(
		'base_url' => 'http://vu.pushlms.com',
	);

	function sendPOST($URL, $XML){

		error_log('SENDING XML VIA '.$URL.' '.$XML."\n");
		
		$HTTPHeaders = Array("Content-Type: text/xml");

		$ch = curl_init($URL);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $HTTPHeaders); 
		curl_setopt($ch, CURLOPT_POSTFIELDS, $XML);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$result = curl_exec($ch);
		
		$cURLInfo = curl_getinfo($ch);
		#error_log('Curl Info: '.print_r($cURLInfo,true));
		
		if (curl_errno($ch)) {
			print "ERROR!!";
			print_r(curl_error($ch));
			exit;
		}

		return array($result, $cURLInfo);

	}

	function getXML($URL){

		error_log('GET XML FROM '.$URL."\n");
		
		$HTTPHeaders = Array("Accept: text/xml");

		// create a new cURL resource
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $URL);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $HTTPHeaders);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		$result = curl_exec($ch);
		error_log($result);
		$cURLInfo = curl_getinfo($ch);
		
		if (curl_errno($ch)) {
			print "ERROR!!";
			print_r(curl_error($ch));
			exit;
		}

		return array($result, $cURLInfo);

	}

	function xml_highlight($s){

		$s = htmlspecialchars($s);

		$s = preg_replace("#&lt;([/]*?)(.*)([\s]*?)&gt;#sU",
			"<font color=\"#0000FF\">&lt;\\1\\2\\3&gt;</font>",$s);

		$s = preg_replace("#&lt;([\?])(.*)([\?])&gt;#sU",
			"<font color=\"#800000\">&lt;\\1\\2\\3&gt;</font>",$s);

		$s = preg_replace("#&lt;([^\s\?/=])(.*)([\[\s/]|&gt;)#iU",
			"&lt;<font color=\"#808000\">\\1\\2</font>\\3",$s);

		$s = preg_replace("#&lt;([/])([^\s]*?)([\s\]]*?)&gt;#iU",
			"&lt;\\1<font color=\"#808000\">\\2</font>\\3&gt;",$s);

		$s = preg_replace("#([^\s]*?)\=(&quot;|')(.*)(&quot;|')#isU",
			"<font color=\"#800080\">\\1</font>=<font color=\"#FF00FF\">\\2\\3\\4</font>",$s);

		$s = preg_replace("#&lt;(.*)(\[)(.*)(\])&gt;#isU",
			"&lt;\\1<font color=\"#800080\">\\2\\3\\4</font>&gt;",$s);

		return nl2br($s);

	}

?>
